import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    // 左侧列表
    leftmenu: sessionStorage.getItem('leftmenu') ? JSON.parse(sessionStorage.getItem('leftmenu')) : [],
    token: sessionStorage.getItem('token') || '',
    // 权限过滤
    auth: sessionStorage.getItem('auth') ? JSON.parse(sessionStorage.getItem('auth')) : [],
    // userId: ''
  },
  mutations: {
    /* setUserId(state, userId) {
      sessionStorage.setItem('userId', userId)
      state.userId = userId
    }, */
    setLeftmenu(state, leftmenu) {
      // 存到sessionStorage
      sessionStorage.setItem('leftmenu', JSON.stringify(leftmenu))
      state.leftmenu = leftmenu
    },
    setToken(state, token) {
      sessionStorage.setItem('token', token)
      state.token = token
    },
    setAuth(state, auth) {
      sessionStorage.setItem('auth', JSON.stringify(auth))
      state.auth = auth
    },
    logout(state) {
      sessionStorage.clear()
      state.token = ''
      state.leftmenu = []
      state.auth = []
    }
  },
  actions: {
  },
  modules: {
  }
})
